package com.linsen.core.poitl.core;

import com.deepoove.poi.XWPFTemplate;
import com.deepoove.poi.config.Configure;
import com.deepoove.poi.config.ConfigureBuilder;
import lombok.AllArgsConstructor;
import lombok.Data;

import java.io.IOException;
import java.io.InputStream;
import java.util.*;

/**
 * @Description:
 * @ProjectName: commons-products-work
 * @Package: net.tsingyun.commons.products.work.guidance.ticket.support.test
 * @ClassName: Test
 * @Author: zhaoyong
 * @Email: zhaoy02@tsingyun.net
 * @Date: 2024/4/9 16:33
 * @Version: 1.0
 */
public class Test {

    public static void main(String[] args) {

    }

    public static void test1 () {
        try {
            MultilevelLoopRowTableRenderPolicy policy = new MultilevelLoopRowTableRenderPolicy("titleName", "sonList");
            Configure config = Configure.builder().bind("list", policy).build();
            InputStream templateIs = Test.class.getClassLoader().getResourceAsStream("template/template.docx");
            XWPFTemplate template = XWPFTemplate.compile(templateIs, config).render(
                    new HashMap<String, Object>() {{
                        put("list", new ArrayList<ExportBo>());
                    }}
            );
            template.writeToFile("XXX.docx");
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    @Data
    public class ExportBo {

        private String titleName;

        private List<Map<String, Object>> sonList;
    }

    public static void test2(){
        try {
            Map<String, Object> params = new HashMap<>();
            params.put("title", "某某某会议");
            params.put("date", new Date());
            params.put("address", "某某会议室");

            List<Report> reports = new ArrayList<>();
            reports.add(new Report("王五", new Date(), "汇报内容1"));
            reports.add(new Report("张三", new Date(), "汇报内容2"));
            reports.add(new Report("李四", new Date(), "汇报内容3"));
            params.put("reports", reports);

            ConfigureBuilder builder = Configure.builder();
            builder.bind("reports", new MultipleRowTableRenderPolicy());
            XWPFTemplate xt = XWPFTemplate
                    .compile("src/test/resources/template/render-multiple-row.docx", builder.build())
                    .render(params);
            xt.writeToFile("render-multiple-row.docx");
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    @Data
    @AllArgsConstructor
    public static class Report {

        private String author;

        private Date time;

        private String content;
    }
}
